package com.zb.response;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RedirectServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 观察重定向请求发现：重定向只是设置响应头参数，等价于如下操作
        /*resp.setHeader("Location", "/img");
        resp.setStatus(HttpServletResponse.SC_FOUND);*/
        resp.sendRedirect("/img");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
